package bairui.international.console.web.controller.user.order;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.servlet.ModelAndView;

import com.lianjing.sh.project.config.web.Project_Config_Web_PageTemplate;
import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.module.context.ModuleContext;
import com.lianjing.sh.spring.web.controller.enhance.navigations.context.NavigationContext;

import bairui.international.model.domain.jpa.TB_ProductOrder;
import bairui.international.model.type.Type_ProductOrder;
import bairui.international.service.Service_ProductOrder;

/**
 *
 * 详情
 *
 * @generated
 * 
 * @see STest_C_User_Order_Detail_DetailAccess 测试
 *
 */
@Controller
public class C_User_Order_Detail_DetailAccess
 extends SC_User_Order_Detail_DetailAccess 
{
	
	@Autowired private Service_ProductOrder service_ProductOrder;
	
	/**
	 * 访问详情页面
	 */
	@Action(DetailAccess.class)
	@GetMapping(DetailAccess.RequestMappingValue)
	public ModelAndView detailAccess(
		ModelMap map, HttpServletRequest request,
		NavigationContext navigationContext, ModuleContext moduleContext, 
		@PathVariable(name=DetailAccess.PathVariableName.UserId) long userId, 
		@PathVariable(name=DetailAccess.PathVariableName.Id) long id
	) throws Exception {
		TB_ProductOrder bean = service_ProductOrder.findById(id);
		/* 模块 */
		moduleContext
			.addModule(module_OrderInfo.module(
					new Module_OrderInfo_OutputModel(bean)
				));
		// 产品信息
		if(bean.getType()== Type_ProductOrder.Buy){
			moduleContext
				.addModule(this.module_OrderProductPage.module(
					new C_User_Order_Detail_OrderProductPage.OrderProductPage.Operate(){
						@Override public Object getUserId() {
							return userId;
						}
						@Override public Object getId() {
							return id;
						}
					}
				));
		}else if(bean.getType()== Type_ProductOrder.Grade){
			moduleContext
				.addModule(this.module_ScoreOrderProductPage.module(
						new C_User_Order_Detail_ScoreOrderProductPage.ScoreOrderProductPage.Operate(){
							@Override public Object getUserId() {
								return userId;
							}
							@Override public Object getId() {
								return id;
							}
						}
					));
		}
		moduleContext
			.addModule(module_UserInfo.module(
					new Module_UserInfo_OutputModel(bean.getUserInfo())
				))
			.addModule(module_AddressInfo.module(
					new Module_AddressInfo_OutputModel(bean.getGoodsInfo())
				));
		//
		return Project_Config_Web_PageTemplate.Admin_Common(request);
	}
	

}
